import { BehaviourNode } from "../BehaviorNode";
import { BehaviorTree } from "../BehaviorTree";
import { RunStatus } from "../IBehaviourTree";

export class Condition extends BehaviourNode {
    externalFunc: () => boolean;
    constructor(name: string, externalFunc: () => boolean) {
        super(name);
        this.externalFunc = externalFunc;
    }
    async Tick(): Promise<any> {
        let status = RunStatus.Completed;
        if (this.externalFunc) {
            if (this.externalFunc()) {
                status = RunStatus.Completed
            } else {
                status = RunStatus.Failure;
            }
        }
        if (BehaviorTree.debug) {
            console.log('条件--',this.nodeName, status)
        }
        return status;
    }
}
